1. Field of the Invention
The invention relates to a technique, specifically a method, apparatus, and article of manufacture that implements the method, which uses offsets in a database management system when an entry has at least one varying-length column. This technique is particularly, though not exclusively, suited for use within a database management system.
2. Description of the Related Art
Database management systems allow large volumes of data to be stored and accessed efficiently and conveniently in a computer system. In a database management system, data is stored in database tables which effectively organize the data into rows (data rows) and columns. A database engine responds to user commands to store and access the data.
In a database table, the columns are associated with a datatype that defines the type of data stored in that column. The datatype may be selected from a set of predefined datatypes such as numeric, integer, decimal, string, character, date, time and timestamp, among others. In a typical database management system, some datatypes assign a predefined length to a column. Such exemplary datatypes include, and are not limited to, “INTEGER,” “DECIMAL,” “DATE,” “TIME,” “TIMESTAMP,” and “CHAR(N)” which allocates space for N bytes in a character column. Other datatypes store data having a varying length such as VARCHAR, Binary Large Object (BLOB), and VARGRAPHIC. A schema is a structure that describes a database table and defines the datatype for each column. The datatype information is stored as column description information.
To more quickly access the data in a database table, an index is generated based on one or more specified columns of the database table. This set of specified columns is referred to as a key or index key. Each row of the database table is associated with a key. The value of the key is determined by the values stored in the columns making up the key. In the index, the values of the keys are ordered. Each key value is associated with a least one record identifier, or pointer, to its associated row of the database table. Therefore, the keys provide access to all the rows in a database table. The database engine accesses the index to quickly locate a row of data in a database table based on the value of the key. Because the columns of a key are derived from the columns of a database table, the columns of the key are associated with a datatype, and this datatype information is stored as column description information for that index.
Typically, an index key or data row that is composed of one or more varying-length columns also contains the length of each varying-length column stored with the data of that column. The column length is used to retrieve individual column values. When an individual column, that is, a specified column, is retrieved, the index key or data row is processed sequentially from the beginning to add the lengths of previous columns to determine the position and length of the specified column. When retrieving data from an index or data row with a large number of varying-length columns, the sequential processing of the columns is slow and performance is poor. Therefore a technique is needed which improves the performance of retrieving data from an index or data row having one or more varying-length columns.
When comparing two fixed-length keys, the column lengths and total key lengths are the same for both keys. Therefore, the two fixed-length keys can be compared with one comparison and no padding of columns is required. However, when comparing two keys containing one or more varying-length columns, the lengths of the corresponding columns of each key can differ, and padding is applied to the shorter columns to make the length of the shorter columns the same as the length of the corresponding columns.
One conventional approach compares the keys one column at a time and logically pads the shorter varying-length columns to match the length of the longer columns. However, this conventional approach is slow and performance is poor. Therefore a technique is needed which improves the performance of comparing keys having at least one varying-length column.